package com.ac.action;

import java.util.List;

import com.ac.entity.Customer;
import com.ac.entity.PN;
import com.ac.util.DataStore;


public class CustomerAction extends BaseAbstractAction{

	/**
	 * 
	 */
	
	private Customer customer;
	private String pnId;
	
	private static final long serialVersionUID = 1L;
	
	private List<PN> pnList;
	
	
	
	

	@Override
	public String execute() {
		return INPUT;
	}
	
	
	public String detail(){
		customer = (Customer) this.getHibernateBaseDao().getObjectByKey(customer.getClass(), customer.getId());
		return "detail";
	}
	
	
	@Override
	public String delete() {
		this.getHibernateBaseDao().delete(customer);
		DataStore.refresh();
		return list();
	}

	@Override
	public String modify() {
		customer = (Customer) this.getHibernateBaseDao().getObjectByKey(customer.getClass(), customer.getId());
		return INPUT;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	@Override
	public String confirm() {
		this.getHibernateBaseDao().saveOrUpdate(customer);
		return RESULT;
	}

	@Override
	public String list() {
		String hql = "from Customer";
		
		try{
			pager = this.getHibernateBaseDao().getPageBySimpleHQL(hql,pager.getOffset());
		}catch(Exception e){
			e.printStackTrace();
		}
		return LIST;
	}


	public String getPnId() {
		return pnId;
	}

	public void setPnId(String pnId) {
		this.pnId = pnId;
	}


	public List<PN> getPnList() {
		return pnList;
	}


	public void setPnList(List<PN> pnList) {
		this.pnList = pnList;
	}

}
